using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class OtherCostDetailMap : EntityTypeConfiguration<OtherCostDetail>
    {
        public OtherCostDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("OtherCostDetails");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.OrderID).HasColumnName("OrderID");
            this.Property(t => t.ProductModelID).HasColumnName("ProductModelID");
            this.Property(t => t.OtherCostFormulaID).HasColumnName("OtherCostFormulaID");
            this.Property(t => t.OtherCostID).HasColumnName("OtherCostID");
            this.Property(t => t.UOMID).HasColumnName("UOMID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Norm).HasColumnName("Norm");

            // Relationships
            this.HasRequired(t => t.Order)
                .WithMany(t => t.OtherCostDetails)
                .HasForeignKey(d => d.OrderID);
            this.HasOptional(t => t.OtherCost)
                .WithMany(t => t.OtherCostDetails)
                .HasForeignKey(d => d.OtherCostID);
            this.HasOptional(t => t.OtherCostFormula)
                .WithMany(t => t.OtherCostDetails)
                .HasForeignKey(d => d.OtherCostFormulaID);
            this.HasOptional(t => t.ProductModel)
                .WithMany(t => t.OtherCostDetails)
                .HasForeignKey(d => d.ProductModelID);
            this.HasOptional(t => t.UOM)
                .WithMany(t => t.OtherCostDetails)
                .HasForeignKey(d => d.UOMID);

        }
    }
}
